rm(list=ls())

library(xtable)

load('dedup-comp.Rdata')

# sample size table


t = data.frame(
  sample = c('2008-2012', '2012-2016','2016-2020', 'Unique voters\n(across samples)'),
  n = c(n_official_1,n_official_2,n_official_3,n_official),
  `n_alt` = c(n1,n2,n3,n)
  
)


t$perc = paste0(round(t$n_alt/t$n*100,2),'\\%')

print(xtable(t), file = 'tables/TabS18.tex')


# correlation table



t = data.frame(
  party = c(rep('Democrat',8),rep('Republican',8)),
  sample = rep(c('2008-2012', '2008-2012',
             '2012-2016', '2012-2016','2012-2016',
             '2016-2020', '2016-2020','2016-2020'),2),
  stat = rep(c('2012', 'Delta 2008-2012',
               '2012', '2016', 'Delta 2012-2016',
               '2016', '2020', 'Delta 2016-2020'
           ),2),
  val = c(lev2.dem.cor1, diff.dem.cor1, 
          lev1.dem.cor2, lev2.dem.cor2, diff.dem.cor2,
          lev1.dem.cor3, lev2.dem.cor3, diff.dem.cor3,
          
          lev2.rep.cor1, diff.rep.cor1, 
          lev1.rep.cor2, lev2.rep.cor2, diff.rep.cor2,
          lev1.rep.cor3, lev2.rep.cor3, diff.rep.cor3
          )
  
)

colnames(t) = c('Exposure', 'Sample', 'Stat', 'Correlation')

print(xtable(t[,c('Sample', 'Exposure','Stat','Correlation')]), file = 'tables/TabS19.tex')


